<!--
 * @Description:div缓冲运动
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-06 06:18:14
 -->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>div缓冲运动</title>
	<style>
		#div1 {
			width: 100px;
			height: 100px;
			background: green;
			position: absolute;
			left:0px;
			top: 50px;
		}

		#div2{
			width: 1px;
			height: 300px;
			position: absolute;
			left: 300px;
			top: 0;
			background: black;
		}
	</style>
	<script>
		window.onload = function () {
			var timer=null
			let odiv = document.getElementById("div1")
		  clearInterval(timer)
			timer=setInterval(()=>{
				var speed=(300-odiv.offsetLeft)/10
				speed=speed>0?Math.ceil(speed):Math.floor(speed)
				odiv.style.left=odiv.offsetLeft+speed+'px'
				document.title=odiv.offsetLeft+'.'+speed
			},40)
		}
	</script>
</head>

<body>
	<div>
		Math.ceil(-9.8) 向上 -9 <br>
		Math.floor(4.8) 向下 4 <br>
		速度=（目标值-当前值）/缩放比例 <br>
		缓冲运动不忘了取整
	</div>
	<div id="div1">
		<span>分享到</span>
	</div>
	<div id="div2"></div>
</body>

</html>